<template>
	<mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="{ auto: true }" :up="{ auto: false }">
		<view class="orderList"><wm-orderlist :datalist="dataList"></wm-orderlist></view>
	</mescroll-uni>
</template>

<script>
import wmOrderlist from './wm-orderlist.vue';
import mescrollUni from '@/mescroll-uni/mescroll-uni.vue';
export default {
	components: {
		mescrollUni,
		wmOrderlist
	},
	props: {
		state: {
			type: [String, Number],
			default: '1'
		},
		urlApi:{
			type:[String],
			default:''
		},
		type: {
			type: [String, Number],
			default: ''
		},
		data: {
			type: Object,
			default: () => {
				return {};
			}
		}
	},
	data() {
		return {
			mygd: '',
			showjz: '',
			dataList: [],
			fun: null,
		};
	},
	methods: {
		// 主动触发下拉刷新
		refresh() {
			this.mescroll.triggerDownScroll();
		},
		mescrollInit() {
			uni.$on('refresh', this.refresh);
			uni.$on('refreshOrderList', this.getlist);
		},
		downCallback(e) {
			this.fun = e;
			e.resetUpScroll();
			this.getlist(e.num);
		},
		upCallback(e) {
			this.fun = e;
			this.getlist(e.num);
		},
		getlist(page = 1) {
			let data = {
				page
			};
			if (this.type == 1) {
				data.state = this.state;
			} else if (this.type == 2) {
				data.timeType = 2;
				data.orderState = this.state;
			} else if (this.type == 3) {
				this.data.orderState = this.state;
			}else if(this.type == 4){
				this.data.orderType = 2;
				this.data.timeType = 1;
				this.data.serviceAt = this.state;
			}
			Object.assign(data, this.data);
			this.util
				.request({
					url: this.urlApi,
					data
				})
				.then(res => {
					if (res.code == 1) {
						if (page == 1) {
							this.dataList = res.data;
						} else {
							this.dataList = this.dataList.concat(res.data);
							console.log(this.dataList);
						}
						this.fun.endSuccess(res.data.length, res.data.length >= 10 ? true : true);
					} else {
						this.fun.endSuccess(0,false);
					}
				})
				.catch(err => {
					this.fun.endErr();
				});
		}
	}
};
</script>

<style lang="scss" scoped>
/deep/.mescroll-uni {
	top: 0rpx !important;
}
.orderList {
	padding: 0 20rpx 20rpx;
}
</style>
